//
//  PointerCorrectVC.swift
//  SDKDebuggingDemo
//
//  Created by 秦晟哲 on 2019/9/21.
//  Copyright © 2019 QinszQSZ. All rights reserved.
//

import UIKit

class PointerCorrectVC: UIViewController {

    @IBOutlet weak var reqTextView: UITextView!
    @IBOutlet weak var rspTextView: UITextView!
    
    private let shell = KCTSingleBLEShell.sharedInstance
    
    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
    }


    @IBAction func clickBack(_ sender: Any) {
        self.navigationController?.popViewController(animated: true)
    }
    @IBAction func clickReq(_ sender: Any) {
        reqTextView.text = nil
        rspTextView.text = nil
        
        let task = KCTOldBLETaskReqPointerCorrect.init {[weak self] (tsk, permit, error) in
            self?.rspTextView.text = ResultContent(title: "请求指针校准", error: error, rspDes: "\(permit)")
        }
        self.reqTextView.text = "请求指针校准"
        shell.resume(baseTask: task)
        
    }
    @IBAction func clickExit(_ sender: Any) {
        reqTextView.text = nil
        rspTextView.text = nil
        let task = KCTOldBLETaskExitPointerCorrect.init()
        self.reqTextView.text = "退出指针校准"
        shell.resume(baseTask: task)
    }
    @IBAction func clickCorrect(_ sender: Any) {
        self.showDateInput(title: "指针校准(1/2)", message: "填写时间:年月日时分秒") {[weak self] (bleDate) in
            
            let phs = ["选择'时'",
                       "选择'分'",
                       "选择'秒'"]
            
            let cs = ["\(bleDate.hour)","\(bleDate.minute)","\(bleDate.second)"]
            
            self?.showMultiTextInput(title: "指针校准(2/2)", message: "选择时间:时分秒", lines: phs.count, placeHolders: phs, contents: cs, completion: {[weak self] (contents) in
                if let h = Int(contents[0]),let m = Int(contents[1]),let s = Int(contents[2]){
                    let task = KCTOldBLETaskSetPointerCorrect.init(time: bleDate, selectHour: h, selectMinute: m, selectSecond: s, completion: {[weak self] (tsk,error) -> (Void) in
                        self?.rspTextView.text = ResultContent(title: "指针校准", error: error, rspDes: nil)
                    })
                    self?.reqTextView.text = ReqContent(title: "指针校准", task: task)
                    self?.shell.resume(baseTask: task)
                }else{
                    SVProgressHUD.showInfo(withStatus: "输入有误")
                }
            })
        }
    }
    
    @IBAction func clickReadStatus(_ sender: Any) {
        
        reqTextView.text = "获取校准状态"
        
        let task = KCTOldBLETaskReadPointerCorrectStatus.init {[weak self] (tsk, status, error) in
            self?.rspTextView.text = ResultContent(title: "获取校准状态", error: error, rspDes: "状态:\(status)")
        }
        shell.resume(baseTask: task)
    }
    
    
    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destination.
        // Pass the selected object to the new view controller.
    }
    */

}
